import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:card_swiper/card_swiper.dart';
import 'package:katana_router/katana_router.dart';
import 'package:thal/backstage/toolkit/utilities/asset_manifest.dart';
import 'package:thal/backstage/toolkit/utilities/color_palette.dart';
import 'package:thal/backstage/toolkit/utilities/dimension_rules.dart';
import 'package:thal/backstage/control_room/user_room.dart';
import 'package:thal/backstage/control_room/check_in_room.dart';
import 'package:thal/backstage/control_room/lake_recommend_room.dart';
import 'package:thal/backstage/control_room/dynamic_room.dart';
import 'package:thal/backstage/control_room/single_chat_room.dart';
import 'package:thal/backstage/control_room/global_state_provider.dart';
import 'package:thal/backstage/toolkit/widgets/authentication_focus_curtain.dart';
import 'package:thal/backstage/toolkit/widgets/report_focus_curtain.dart';
import 'package:thal/playbill/central_stage/check_in_production.dart';
import 'package:thal/playbill/central_stage/lake_recommend_production.dart';
import 'package:thal/playbill/central_stage/answer_production.dart';
import 'package:thal/playbill/community_forum/dynamic_production.dart';

/// 首页 - 中央舞台
class HomeProduction extends StatefulWidget {
  const HomeProduction({super.key});

  @override
  State<HomeProduction> createState() => _HomeProductionState();
}

class _HomeProductionState extends State<HomeProduction> {
  late UserRoom _userRoom;
  late CheckInRoom _checkInRoom;
  late LakeRecommendRoom _lakeRecommendRoom;
  late DynamicRoom _dynamicRoom;
  late SingleChatRoom _singleChatRoom;

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    _userRoom = GlobalStateProvider.userRoomOf(context);
    _checkInRoom = GlobalStateProvider.checkInRoomOf(context);
    _lakeRecommendRoom = GlobalStateProvider.lakeRecommendRoomOf(context);
    _dynamicRoom = GlobalStateProvider.dynamicRoomOf(context);
    _singleChatRoom = GlobalStateProvider.singleChatRoomOf(context);
  }

  /// 构建固定标题栏
  Widget _buildFixedHeader() {
    return Observer(
      builder:
          (context) => Container(
            height: 60.h,
            padding: EdgeInsets.symmetric(horizontal: 16.w),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                // 左侧标题
                Text('Thal')
                    .fontSize(30.sp)
                    .textColor(ColorPalette.black)
                    .carterOne(weight: FontWeight.w400),
                // 右侧用户头像
                _buildUserAvatar(),
              ],
            ),
          ),
    );
  }

  /// 构建用户头像
  Widget _buildUserAvatar() {
    return Observer(
      builder: (context) {
        if (_userRoom.isLoggedIn) {
          final currentUser = _userRoom.fetchCurrentUser();
          if (currentUser != null) {
            return Container(
              width: 40.w,
              height: 40.w,
              decoration: BoxDecoration(
                shape: BoxShape.circle,
                image: DecorationImage(
                  image: AssetImage(currentUser.avatar),
                  fit: BoxFit.cover,
                ),
              ),
            ).withTapEffect(onTap: _handleLoginTest, scaleFactor: 0.9);
          }
        }

        // 未登录时显示默认头像
        return Container(
          width: 40.w,
          height: 40.w,
          decoration: BoxDecoration(
            shape: BoxShape.circle,
            color: ColorPalette.blue1,
          ),
          child: Icon(Icons.person, color: Colors.white, size: 24.w),
        ).withTapEffect(onTap: _handleLoginTest, scaleFactor: 0.9);
      },
    );
  }

  /// 构建打卡卡片
  Widget _buildCheckInCard() {
    return AspectRatio(
      aspectRatio: 358 / 191,
      child: Container(
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage(AssetManifest.homeCheckCard),
            fit: BoxFit.fill,
          ),
        ),
        child: Observer(builder: (context) => _buildCheckInContent()),
      ),
    ).wrapHorizontal(16.w);
  }

  /// 构建打卡内容
  Widget _buildCheckInContent() {
    final now = DateTime.now();
    final weekdays = ['Mon.', 'Tue.', 'Wed.', 'Thu.', 'Fri.', 'Sat.', 'Sun.'];

    return Column(
      children: [
        8.h.heightBox,
        // 顶部日期和按钮
        Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            // 左侧日期
            Row(
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Text('${now.day}')
                    .fontSize(48.sp)
                    .textColor(Colors.black)
                    .carterOne(weight: FontWeight.w400),
                6.w.widthBox,
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text('${_getMonthName(now.month)}.')
                        .fontSize(12.sp)
                        .textColor(Colors.black)
                        .carterOne(weight: FontWeight.w400),
                    2.h.heightBox,
                    Text('25° Clear', style: TextStyle(height: 1.57))
                        .fontSize(14.sp)
                        .textColor(Colors.black)
                        .arimo(weight: FontWeight.w400),
                  ],
                ),
              ],
            ),

            // 右侧按钮
            ElevatedButton(
              onPressed: _handleButtonTap,
              style: ElevatedButton.styleFrom(
                backgroundColor: ColorPalette.blue1,
                foregroundColor: Colors.white,
                padding: EdgeInsets.symmetric(horizontal: 32.w, vertical: 4.h),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(25.r),
                ),
                elevation: 0,
              ),
              child: Text(
                _userRoom.isLoggedIn ? 'Check Record' : 'Sign In',
              ).fontSize(14.sp).arimo(weight: FontWeight.w700),
            ).wrapTop(12.h).withTapEffect(onTap: _handleButtonTap),
          ],
        ),
        Spacer(),
        // 周一到周天的打卡状态
        Row(
          children:
              weekdays.asMap().entries.map((entry) {
                final index = entry.key;
                final dayName = entry.value;
                final dayDate = _getWeekdayDate(index);

                return Expanded(
                  child: Padding(
                    padding: EdgeInsets.only(
                      right: index < weekdays.length - 1 ? 4.w : 0,
                    ),
                    child: _buildDayStatus(dayName, dayDate, index),
                  ),
                );
              }).toList(),
        ),
      ],
    ).wrapAll(14.w);
  }

  /// 构建单天状态
  Widget _buildDayStatus(String dayName, DateTime dayDate, int index) {
    final now = DateTime.now();
    final isToday = _isSameDay(dayDate, now);
    final isPast = dayDate.isBefore(now) && !isToday;

    return Observer(
      builder: (context) {
        bool isChecked = false;
        if (_userRoom.isLoggedIn && (isPast || isToday)) {
          final currentUser = _userRoom.fetchCurrentUser();
          if (currentUser != null) {
            isChecked = _checkInRoom.hasCheckedInOnDate(
              currentUser.id,
              dayDate,
            );
          }
        }

        // 确定外层盒子背景颜色和圆形背景颜色（根据日期类型）
        Color containerBgColor;
        Color circleBgColor;
        Color dateTextColor;

        if (isPast) {
          // 过去日期：灰色
          containerBgColor = ColorPalette.white;
          circleBgColor = ColorPalette.blue1;
          dateTextColor = ColorPalette.blue1;
        } else if (isToday) {
          // 今天：白色
          containerBgColor = ColorPalette.white;
          circleBgColor = ColorPalette.blue1;
          dateTextColor = ColorPalette.blue1;
        } else {
          // 未来日期：浅蓝色
          containerBgColor = ColorPalette.blue2;
          circleBgColor = ColorPalette.white;
          dateTextColor = ColorPalette.white;
        }

        return Container(
          padding: EdgeInsets.all(3.w),
          decoration: ShapeDecoration(
            color: containerBgColor,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(21.r),
            ),
          ),
          child: Column(
            children: [
              8.h.heightBox,
              // 顶部星期
              Text(dayName)
                  .fontSize(14.sp)
                  .textColor(dateTextColor)
                  .arimo(weight: FontWeight.w700),
              2.h.heightBox,
              // 底部圆形状态
              Container(
                width: 36.w,
                height: 36.w,
                padding: EdgeInsets.all(6.w),
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  color: circleBgColor,
                ),
                child: Center(
                  child:
                      isChecked
                          ? Image.asset(AssetManifest.check)
                          : isPast && !isChecked
                          ? Image.asset(AssetManifest.uncheck)
                          : Text('${dayDate.day}')
                              .fontSize(16.sp)
                              .textColor(ColorPalette.blue2)
                              .arimo(weight: FontWeight.w700),
                ),
              ),
              2.h.heightBox,
            ],
          ),
        );
      },
    );
  }

  /// 构建湖泊推荐图片
  Widget _buildLakeRecommendImage() {
    return Observer(
      builder: (context) {
        final lakes = _lakeRecommendRoom.fetchAllLakeRecommends();
        if (lakes.isEmpty) return SizedBox.shrink();

        final randomLake =
            lakes[DateTime.now().millisecondsSinceEpoch % lakes.length];

        return Container(
              width: double.infinity,
              height: 250.h,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(16.r),
                image: DecorationImage(
                  image: AssetImage(randomLake.imageUrl),
                  fit: BoxFit.cover,
                ),
              ),
              child: Stack(
                children: [
                  // 毛玻璃效果信息框
                  Positioned(
                    bottom: 16.h,
                    left: 16.w,
                    right: 16.w,
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(16.r),
                      child: BackdropFilter(
                        filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
                        child: Container(
                          padding: EdgeInsets.symmetric(
                            horizontal: 12.w,
                            vertical: 8.h,
                          ),
                          decoration: BoxDecoration(
                            color: Colors.white.withOpacity(0.03),
                            borderRadius: BorderRadius.circular(16.r),
                            border: Border.all(
                              color: Colors.white.withOpacity(0.3),
                              width: 1,
                            ),
                          ),
                          child: Row(
                            children: [
                              Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text(randomLake.title)
                                      .fontSize(20.sp)
                                      .textColor(Colors.white)
                                      .arimo(weight: FontWeight.w700),
                                  Text(randomLake.location)
                                      .fontSize(11.sp)
                                      .textColor(Colors.white)
                                      .arimo(weight: FontWeight.w400),
                                ],
                              ),
                              Spacer(),
                              Container(
                                width: 40.w,
                                height: 40.w,
                                decoration: ShapeDecoration(
                                  color: Colors.white.withValues(alpha: 0.19),
                                  shape: OvalBorder(),
                                ),
                                child: Icon(
                                  Icons.chevron_right_rounded,
                                  size: 30.w,
                                  color: Colors.white,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            )
            .withTapEffect(
              onTap: () {
                context.router.push(
                  LakeRecommendProduction.query(lakeId: randomLake.id),
                );
              },
              scaleFactor: 0.98,
            )
            .wrapHorizontal(16.w)
            .wrapVertical(16.h);
      },
    );
  }

  /// 构建用户动态轮播图
  Widget _buildDynamicCarousel() {
    return Observer(
      builder: (context) {
        final dynamics = _dynamicRoom.fetchAllDynamics();
        if (dynamics.isEmpty) return SizedBox.shrink();

        return Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text('Hot News')
                .fontSize(20.sp)
                .textColor(ColorPalette.black)
                .carterOne(weight: FontWeight.bold)
                .wrapHorizontal(16.w),
            12.h.heightBox,
            SizedBox(
              height: 322.h,
              child: Swiper(
                itemBuilder: (BuildContext context, int index) {
                  final dynamic = dynamics[index];
                  return GestureDetector(
                    onTap: () {
                      context.router.push(
                        DynamicProduction.query(dynamicId: dynamic.id),
                      );
                    },
                    child: Container(
                      margin: EdgeInsets.symmetric(horizontal: 8.w),
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(12.r),
                        image: DecorationImage(
                          image: AssetImage(
                            dynamic.mediaType == 'video' &&
                                    dynamic.thumbnailUrls.isNotEmpty &&
                                    dynamic.thumbnailUrls[0] != null
                                ? dynamic.thumbnailUrls[0]!
                                : dynamic.mediaUrls.isNotEmpty
                                ? dynamic.mediaUrls[0]
                                : '',
                          ),
                          fit: BoxFit.cover,
                        ),
                      ),
                      child: Stack(
                        children: [
                          // 顶部信息
                          Positioned(
                            top: 16.h,
                            left: 16.w,
                            right: 16.w,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      mainAxisAlignment:
                                          MainAxisAlignment.start,
                                      children: [
                                        Text(
                                              _formatDate(dynamic.createdAt),
                                              style: TextStyle(height: 1.82),
                                            )
                                            .textColor(Colors.white)
                                            .fontSize(12.sp)
                                            .arimo(weight: FontWeight.w700),
                                        Container(
                                          width: 90.w,
                                          height: 2.w,
                                          color: Colors.white,
                                        ),
                                      ],
                                    )
                                    .fontSize(11.sp)
                                    .textColor(Colors.white)
                                    .arimo(weight: FontWeight.w700),
                                Text(_getUserDisplayName(dynamic.userId))
                                    .fontSize(14.sp)
                                    .textColor(Colors.white)
                                    .arimo(weight: FontWeight.w700),
                              ],
                            ),
                          ),
                          // 中央标题和举报按钮
                          Positioned(
                            top: 100.h,
                            left: 16.w,
                            right: 16.w,
                            child: Row(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Expanded(
                                  child: Text(
                                    dynamic.title,
                                    style: TextStyle(
                                      fontSize: 20.sp,
                                      fontWeight: FontWeight.bold,
                                      color: Colors.white,
                                      height: 1.2,
                                    ),
                                    maxLines: 2,
                                    overflow: TextOverflow.ellipsis,
                                  ),
                                ),
                                8.w.widthBox,
                                Container(
                                  width: 20.w,
                                  height: 20.w,
                                  decoration: BoxDecoration(
                                    image: DecorationImage(
                                      image: AssetImage(AssetManifest.report),
                                      fit: BoxFit.cover,
                                    ),
                                    shape: BoxShape.circle,
                                  ),
                                ).withTapEffect(
                                  onTap: () => _handleReportDynamic(dynamic.id),
                                  scaleFactor: 0.9,
                                ),
                              ],
                            ),
                          ),
                          // 描述内容
                          Positioned(
                            top: 160.h,
                            left: 16.w,
                            right: 16.w,
                            child: Text(
                              dynamic.content,
                              style: TextStyle(
                                fontSize: 14.sp,
                                color: Colors.white,
                                height: 1.3,
                              ),
                              maxLines: 3,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ),
                          // 底部交互按钮
                          Positioned(
                            bottom: 16.h,
                            left: 16.w,
                            right: 16.w,
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                _buildInteractionButton(
                                  AssetManifest.comment,
                                  '${dynamic.comments.length}',
                                  backgroundColor: ColorPalette.white,
                                  textColor: Colors.black,
                                  iconSize: 18.w, // 左侧评论按钮图标大小
                                ),
                                Observer(
                                  builder: (context) {
                                    return _buildInteractionButton(
                                      AssetManifest.chat,
                                      '',
                                      backgroundColor: Colors.white.withValues(
                                        alpha: 0.23,
                                      ),
                                      textColor: ColorPalette.white,
                                      iconSize: 26.w, // 中间聊天按钮图标大小
                                    ).withTapEffect(
                                      onTap:
                                          () =>
                                              _handleChatButton(dynamic.userId),
                                      scaleFactor: 0.9,
                                    );
                                  },
                                ),
                                Observer(
                                  builder: (context) {
                                    final currentUser =
                                        _userRoom.fetchCurrentUser();
                                    final isLiked =
                                        currentUser != null &&
                                        _dynamicRoom.isLikedByUser(
                                          dynamic.id,
                                          currentUser.id,
                                        );

                                    return _buildInteractionButton(
                                      isLiked
                                          ? AssetManifest.like
                                          : AssetManifest.unlike,
                                      '${dynamic.likes.length}',
                                      backgroundColor:
                                          isLiked
                                              ? ColorPalette.pink
                                              : ColorPalette.white,
                                      textColor:
                                          isLiked
                                              ? ColorPalette.white
                                              : Colors.black,
                                      iconSize: 18.w, // 右侧点赞按钮图标大小
                                      isLiked: isLiked,
                                    ).withTapEffect(
                                      onTap: () {
                                        if (currentUser != null) {
                                          _dynamicRoom.toggleLike(
                                            dynamic.id,
                                            currentUser.id,
                                          );
                                        } else {
                                          // 未登录时显示登录弹窗
                                          AuthenticationSpotlight.illuminate(
                                            context,
                                          );
                                        }
                                      },
                                      scaleFactor: 0.9,
                                    );
                                  },
                                ),
                              ],
                            ),
                          ),
                        ],
                      ),
                    ),
                  );
                },
                itemCount: dynamics.length,
                control: SwiperControl(
                  iconPrevious: Icons.arrow_back_ios,
                  iconNext: Icons.arrow_forward_ios,
                  color: ColorPalette.blue1,
                  size: 20.w,
                ),
                viewportFraction: 0.7,
                scale: 0.8,
                autoplay: false,
                loop: true,
                duration: 300,
                curve: Curves.easeInOut,
              ),
            ),
          ],
        );
      },
    );
  }

  /// 构建交互按钮
  Widget _buildInteractionButton(
    String image,
    String count, {
    bool isLiked = false,
    Color? backgroundColor,
    Color? textColor,
    double? iconSize, // 改为可选参数
  }) {
    final iconSizeValue = iconSize ?? 20.w; // 在方法内部处理默认值
    final bgColor = backgroundColor ?? (isLiked ? Colors.pink : Colors.white);
    final txtColor = textColor ?? (isLiked ? Colors.white : Colors.black);

    return ClipRRect(
      borderRadius: BorderRadius.circular(8.r),
      child: BackdropFilter(
        filter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
        child: Container(
          padding: EdgeInsets.symmetric(horizontal: 12.w, vertical: 8.h),
          decoration: BoxDecoration(
            color: bgColor,
            borderRadius: BorderRadius.circular(8.r),
          ),
          child: Row(
            mainAxisSize: MainAxisSize.min,
            children: [
              Image.asset(
                image,
                width: iconSizeValue,
                height: iconSizeValue,
                color: txtColor,
              ),
              if (count.isNotEmpty) ...[
                6.w.widthBox,
                Text(count, style: TextStyle(height: 1.43))
                    .fontSize(14.sp)
                    .textColor(txtColor)
                    .arimo(weight: FontWeight.w700),
              ],
            ],
          ),
        ),
      ),
    );
  }

  /// 构建答题图片
  Widget _buildQuizImage() {
    return Container(
          width: double.infinity,
          height: 211.h,
          decoration: BoxDecoration(
            image: DecorationImage(
              image: AssetImage(AssetManifest.questionImage),
              fit: BoxFit.fill,
            ),
          ),
        )
        .withTapEffect(onTap: _handleQuizTap)
        .wrapHorizontal(16.w)
        .wrapVertical(16.h);
  }

  /// 处理答题按钮点击
  void _handleQuizTap() {
    if (!_userRoom.isLoggedIn) {
      AuthenticationSpotlight.illuminate(context);
    } else {
      context.router.push(AnswerProduction.query());
    }
  }

  /// 处理登录测试
  void _handleLoginTest() {
    if (_userRoom.isLoggedIn) {
    } else {
      AuthenticationSpotlight.illuminate(context);
    }
  }

  /// 处理按钮点击
  void _handleButtonTap() {
    // 检查用户登录状态
    if (!_userRoom.isLoggedIn) {
      // 如果用户未登录，显示登录弹窗
      AuthenticationSpotlight.illuminate(context);
    } else {
      // 如果用户已登录，跳转到打卡页面

      context.router.push(CheckInProduction.query());
    }
  }

  /// 处理举报动态
  void _handleReportDynamic(String dynamicId) {
    ReportAccusation.raise(
      context,
      targetId: dynamicId,
      targetType: 'dynamic',
      onReportSubmitted: (reason) {
        // 举报后删除动态
        _dynamicRoom.deleteDynamic(dynamicId);
        ScaffoldMessenger.of(context).showSnackBar(
          SnackBar(
            content: Text('Dynamic reported and removed'),
            backgroundColor: ColorPalette.blue1,
          ),
        );
      },
    );
  }

  /// 处理聊天按钮点击
  void _handleChatButton(String targetUserId) {
    final currentUser = _userRoom.fetchCurrentUser();

    // 检查用户是否登录
    if (currentUser == null) {
      AuthenticationSpotlight.illuminate(context);
      return;
    }

    // 检查用户是否尝试与自己聊天
    if (currentUser.id == targetUserId) {
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text('You cannot chat with yourself'),
          backgroundColor: ColorPalette.blue1,
        ),
      );
      return;
    }

    // 检查是否已存在对话
    final existingChat = _singleChatRoom.fetchSingleChatBetweenUsers(
      currentUser.id,
      targetUserId,
    );

    if (existingChat != null) {
      // 如果已存在对话，直接跳转（暂未实现）
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text('Opening chat...'),
          backgroundColor: ColorPalette.blue1,
        ),
      );
      // TODO: 跳转到聊天页面
      // Navigator.push(...);
    } else {
      // 如果不存在对话，创建新对话并跳转（暂未实现）
      _singleChatRoom.createSingleChat(currentUser.id, targetUserId);
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text('Chat created successfully'),
          backgroundColor: ColorPalette.blue1,
        ),
      );
      // TODO: 跳转到聊天页面
      // Navigator.push(...);
    }
  }

  /// 获取月份名称
  String _getMonthName(int month) {
    const months = [
      'Jan',
      'Feb',
      'Mar',
      'Apr',
      'May',
      'Jun',
      'Jul',
      'Aug',
      'Sep',
      'Oct',
      'Nov',
      'Dec',
    ];
    return months[month - 1];
  }

  /// 获取周几对应的日期
  DateTime _getWeekdayDate(int weekdayIndex) {
    final now = DateTime.now();
    final startOfWeek = now.subtract(Duration(days: now.weekday - 1));
    return startOfWeek.add(Duration(days: weekdayIndex));
  }

  /// 判断是否为同一天
  bool _isSameDay(DateTime date1, DateTime date2) {
    return date1.year == date2.year &&
        date1.month == date2.month &&
        date1.day == date2.day;
  }

  /// 格式化日期
  String _formatDate(DateTime date) {
    const months = [
      'January',
      'February',
      'March',
      'April',
      'May',
      'June',
      'July',
      'August',
      'September',
      'October',
      'November',
      'December',
    ];
    return '${months[date.month - 1]} ${date.day}th';
  }

  /// 获取用户显示名称
  String _getUserDisplayName(String userId) {
    final user = _userRoom.fetchUserById(userId);
    return user?.username ?? 'Unknown';
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: double.infinity,
        height: double.infinity,
        decoration: BoxDecoration(
          image: DecorationImage(
            image: AssetImage(AssetManifest.screenBackground),
            fit: BoxFit.cover,
          ),
        ),
        child: SafeArea(
          bottom: false,
          child: Column(
            children: [
              // 固定标题栏
              _buildFixedHeader(),
              // 可滚动内容
              Expanded(
                child: SingleChildScrollView(
                  child: Column(
                    children: [
                      // 打卡卡片
                      _buildCheckInCard(),
                      16.h.heightBox,
                      // 湖泊推荐图片
                      _buildLakeRecommendImage(),
                      // 用户动态轮播图
                      _buildDynamicCarousel(),
                      16.h.heightBox,
                      // 答题图片
                      _buildQuizImage(),
                      120.h.heightBox,
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
